using System;
using System.Collections.Generic;
using System.Text;

namespace Evolution.Engine.Items
{
    public class ItemCost
    {
        private int _Cost = 0;
        private int _Platinum = 0;
        private int _Gold = 0;
        private int _Silver = 0;
        private int _Copper = 0;

        public ItemCost(int Cost)
        {
            _Cost = Cost;

            int cost = _Cost;

            if (cost > 10000)
            {
                _Platinum = (int)(cost / 10000);
                cost -= (10000 * (int)(cost / 10000));
            }

            if (cost > 1000)
            {
                _Gold = (int)(cost / 1000);
                cost -= (1000 * (int)(cost / 1000));
            }

            if (cost > 1000)
            {
                _Silver = (int)(cost / 1000);
                cost -= (1000 * (int)(cost / 1000));
            }

            if (cost > 0)
                _Copper = cost;
        }

        public override string ToString()
        {
            string retVal = "";
            int tmp = 0;

            if (_Platinum > 0)
            {
                retVal += string.Format("P{0}", _Platinum);
                tmp++;
            }

            if (_Gold > 0)
            {
                if (retVal.Length > 0) retVal += ":";
                retVal += string.Format("G{0}", _Gold);
                tmp++;
            }

            if (_Silver > 0)
            {
                if (retVal.Length > 0) retVal += "\n";
                retVal += string.Format("S{0}", _Silver);
                tmp++;
            }

            if (_Copper > 0)
            {
                if (tmp > 1) retVal += "\n";
                if (retVal.Length > 0) retVal += ":";
                retVal += string.Format("C{0}", _Copper);
            }

            return retVal;
        }

        public int Platinum { get { return _Platinum; } }
        public int Gold { get { return _Gold; } }
        public int Silver { get { return _Silver; } }
        public int Copper { get { return _Copper; } }
        public int TotalCopper
        {
            get
            {
                return (10000 * _Platinum) +
                    (1000 * _Silver) +
                    (100 * _Gold) +
                    (_Copper * 1);
            }
        }

        #region Item Cost Operator definitions and implementation
        public static ItemCost operator +(ItemCost item, ItemCost item1)
        {
            return new ItemCost(item1.TotalCopper + item.TotalCopper);
        }
        public static ItemCost operator -(ItemCost item, ItemCost item1)
        {
            return new ItemCost(item1.TotalCopper - item.TotalCopper);
        }
        public static bool operator ==(ItemCost item, ItemCost item1)
        {
            return item.TotalCopper == item1.TotalCopper;
        }
        public static bool operator !=(ItemCost item, ItemCost item1)
        {
            return item.TotalCopper != item1.TotalCopper;
        }
        public static bool operator ==(ItemCost item, float item1)
        {
            return (float)item.TotalCopper == item1;
        }
        public static bool operator !=(ItemCost item, float item1)
        {
            return (float)item.TotalCopper != item1;
        }
        public static bool operator ==(ItemCost item, int item1)
        {
            return item.TotalCopper == item1;
        }
        public static bool operator !=(ItemCost item, int item1)
        {
            return item.TotalCopper != item1;
        }
        public static bool operator >=(ItemCost item, ItemCost item1)
        {
            return item.TotalCopper >= item1.TotalCopper;
        }
        public static bool operator <=(ItemCost item, ItemCost item1)
        {
            return item.TotalCopper <= item1.TotalCopper;
        }
        public static bool operator >=(ItemCost item, float item1)
        {
            return (float)item.TotalCopper >= item1;
        }
        public static bool operator <=(ItemCost item, float item1)
        {
            return (float)item.TotalCopper <= item1;
        }
        public static bool operator >=(ItemCost item, int item1)
        {
            return item.TotalCopper >= item1;
        }
        public static bool operator <=(ItemCost item, int item1)
        {
            return item.TotalCopper <= item1;
        }
        #endregion
    }
}
